home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #23 (Aug 87) / MacHac source / validSrc.c
Text File  |  1987-06-25  |  1KB  |  33 lines

  1. /* Lightspeed C 2.01 source, based on the ValidPointer(), and Validhandle()    */
  2. /* routines in the Programmers Extender Vol 1 by Invention Software Inc.    */
  3.  
  4. Boolean ValidPointer(P)
  5. Ptr        P;
  6. {
  7.     if ((P == NULL) || ((long)P & 1L))        /* if pointer is NULL or odd    */
  8.         return(FALSE);                        /* then pointer is definitely bad!    */
  9.  
  10. /* In my opinion test for null should be ommitted, indexing into an array    */
  11. /* of characters (bytes) could result in a valid pointer to an odd address    */
  12.  
  13. /* another test which should be added here is a check to see that the        */
  14. /* pointer is not above the tom of RAM, but MemTop() does not return the    */
  15. /* correct value when running under switcher or servant.                    */
  16.  
  17.     else
  18.         return(TRUE);                        /* else pointer is potentially valid*/
  19.  
  20. Boolean ValidHandle(H)
  21. Handle    H;
  22. {
  23.     Ptr        P;
  24.  
  25.     if (ValidPointer((Ptr)H)) {                /* the handle dereferenced is OK    */
  26.         P = (Ptr)((long)(*H) & 0x00FFFFFF);    /* mask off the master pointer status bits */
  27.         if (ValidPointer((Ptr)P))            /* the pointer pointed to is OK    */
  28.             return(TRUE);                    /* then Handle is potentially valid    */
  29.     }
  30.     return(FALSE);                            /* Handle doesn't point to a pointer */
  31. }